/**
 * 
 */
package testing;

import interfaces.IFocalElement;
import interfaces.IHypothesis;

import java.util.ArrayList;
import java.util.Hashtable;

import massDistribution.MassDistribution;
import core.FrameOfDiscernment;
import core.Hypothesis;
import engine.ReputationManager;

/**
 * @author Elisa Costante
 * 
 */
public class EngineMain {

	static String hyphotesiesFileName = "Hypothesis.txt";

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		Hashtable<String, Hypothesis> trustMapping = new Hashtable<String, Hypothesis>();
		ArrayList<IHypothesis> allHypothesies = new ArrayList<IHypothesis>();

		int numericalValue = (int) 'A';
		int numberOfHypothesis = 5;

		for (int i = 0; i < numberOfHypothesis; i++) {

			String name = new String(Character.toString((char) numericalValue));
			Hypothesis hypoyhesis = new Hypothesis(name, 0);
			trustMapping.put(name, hypoyhesis);
			allHypothesies.add(hypoyhesis);
			numericalValue++;

		}

		FrameOfDiscernment frame = new FrameOfDiscernment(allHypothesies);

		ArrayList<MassDistribution> masses = new ArrayList<MassDistribution>();
		ReadTestUtility.readInput("test1.txt", masses);

		mapHyphotesis(masses, trustMapping);

		ReputationManager reputationManager = new ReputationManager(null, frame);
		// // // reputationManager.setMassDistribution(masses);
		// // double k = 0.5;
		// // //double reputation = reputationManager.getReputation(
		// // JointOperator.DEMPSTER, BestResultPolicy.BEST_BPA,
		// // ReputationKind.MIDDLE_POINT_REPUTATION, k);
		// // System.out.println("" + JointOperator.DEMPSTER.getName() + " :"
		// // + reputation);
		// // //reputation =
		// reputationManager.getReputation(JointOperator.AVERAGE,
		// // BestResultPolicy.BEST_BPA,
		// // ReputationKind.MIDDLE_POINT_REPUTATION, k);
		// // System.out.println("" + JointOperator.AVERAGE.getName() + " :"
		// // + reputation);
		// // // reputation =
		// reputationManager.getReputation(JointOperator.YAGER,
		// // // BestResultPolicy.BEST_BPA,
		// // // ReputationKind.MIDDLE_POINT_REPUTATION, k);
		// // // System.out.println("" + JointOperator.YAGER.getName() + " :"
		// // // + reputation);
		// // //reputation =
		// reputationManager.getReputation(JointOperator.DISTANCE,
		// // BestResultPolicy.BEST_BPA,
		// // ReputationKind.MIDDLE_POINT_REPUTATION, k);
		// // System.out.println("" + JointOperator.DISTANCE.getName() + " :"
		// + reputation);
	}

	/**
	 * @param masses
	 * @param trustMapping
	 */
	private static void mapHyphotesis(ArrayList<MassDistribution> masses,
			Hashtable<String, Hypothesis> trustMapping) {
		for (MassDistribution massDistribution : masses) {
			ArrayList<IFocalElement> focalElements = massDistribution
					.getBodyOfEvidence();
			for (IFocalElement focalElement : focalElements) {
				ArrayList<IHypothesis> allHypothesies = focalElement
						.getElement().getHypothesies();
				ArrayList<IHypothesis> newHypothesies = new ArrayList<IHypothesis>(
						allHypothesies.size());
				for (IHypothesis hypothesis : allHypothesies) {
					Hypothesis newHypothesis = trustMapping.get(hypothesis
							.getIdentifier());
					newHypothesies.add(newHypothesis);

				}
				focalElement.getElement().setHypothesies(newHypothesies);
			}
		}

	}
}
